using System;
using System.Threading;

namespace Nice157Advices.Advices
{
    /// <summary>
    /// 65.总是处理未捕获的异常
    /// </summary>
    public static class _65
    {
        public static void Go ()
        {
            // 控制台下
            // 其他类型的程序也有对应的
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler (_65.CurrentDomain_UnhandledException);
            int i = 0;
            var z = 10 / i;
        }

        private static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs args)
        {
            Exception error = (Exception) args.ExceptionObject;
            System.Console.WriteLine ("MyHandler caught: " + error.Message);
        }
    }
}